package com.atguigu.gmall.order.config;

import com.atguigu.gmall.common.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author mqx
 * @date 2020-8-13 10:43:18
 */
@Configuration
public class OrderCanelMqConfig {

    // 设置队列
    @Bean
    public Queue orderDealyQueue(){
        // 返回
        return new Queue(MqConst.QUEUE_ORDER_CANCEL,true);
    }
    // 设置交换机
    @Bean
    public CustomExchange orderCustomExchange(){
        // 声明一个arguments 集合。
        HashMap<String, Object> arguments = new HashMap<>();
        // 设置一个参数
        arguments.put("x-delayed-type","direct");

        // 返回一个
        // 交换机的名称,第二个是交换机类型key，
        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message",true,false,arguments);
    }
    // 设置绑定关系
    @Bean
    public Binding orderBinding(){
        // 返回绑定关系
        return BindingBuilder.bind(orderDealyQueue()).to(orderCustomExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }

}
